var express = require('express');
var router = express.Router();
const mongodb= require('../components/mongo');

const multer = require('multer');
const uploader = multer({dest:'uploads/'});

/* GET home page. */
router.get('/',async function(req, res, next) {
   console.log(req.query.u_id);
   var m_uid = req.query.u_id;
   if(m_uid==undefined){
	   //don't' have id
	   res.json({   
		       errno: 0,
		       errmsg: "",
		       data: {
		           res: false
		       }   
	   })
   }else{
	   const result = await mongodb.find("Article",{u_id:m_uid});
	   if(result.length>0){
		   //hav article
		   res.json({
		   		   
		   		       errno: 0,
		   		       errmsg: "",
		   		       data: {
		   		           res: true,
						   articles:result,
		   		       }
		   		   
		   })
		   
	   }else{
		   // don' hav article
		   res.json({
		   		   
		   		       errno: 0,
		   		       errmsg: "",
		   		       data: {
		   		           res: false
		   		       }
		   		   
		   })
	   }
   }

});


module.exports = router;